/* linkit.js
 * By François Leporcq
 * MIT Licensed.
 */
var AbstractShape = $Class.extend({
    _className: "AbstractShape",
    setPartOfComposite: function(bool){
        this._partOfComposite = bool;
    },
    isPartOfComposite: function(){
        return this._partOfComposite;
    },
    setOrigin: function(origin){
        this._origin = origin;
    },
    getOrigin: function(){
        return this._origin;
    },
    getBox: function(){
        throw new Error("The 'getBox()' method must be overrided in '" + this._className + "' class");
    },
    afterWorkspaceAdd: function(drawer){

    },
    addLink: function(link){
        this.throwErrorIfNotLinkable();
        if(!this._links){
            this._links = new Array();
        }
        this._links.push(link);
    },
    removeLink: function(link){
        this.throwErrorIfNotLinkable();
        if(link == null){
            return
        }
        for(var i = 0 ; i < this._links.length ; i++){
            if(this._links[i] === link){
                this.getShapes().splice(i,1);
                return link;
            }
        }
        return null;
    },
    removeAllLinks: function(){
        this.throwErrorIfNotLinkable();
        if(this._links == null){
            return;
        }
        delete this._links;
    },
    getLinks: function(){
        this.throwErrorIfNotLinkable();
        return this._links;
    },
    hasLinks: function(){
        return this._links != null;
    },
    throwErrorIfNotLinkable: function(){
        if(!this.implementationOf(Linkable)){
            throw new Error("This object (" +this._className + ") is not linkable");
        }
    }

},true);